package com.example.myapplication.ui;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;

import com.example.myapplication.R;
import com.example.myapplication.databinding.ActivityWelcomeBinding;

public class WelcomeActivity extends AppCompatActivity {
    private ActivityWelcomeBinding binding;
    AddNoteFragment addNoteFragment;
    NoteListFragment noteListFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityWelcomeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initMethod();

    }

    private void initMethod() {
        // 初始化 Fragment
        noteListFragment = new NoteListFragment();
        addNoteFragment = new AddNoteFragment();
        // 默认显示 NoteFragment
        replaceFragment(noteListFragment);
        //点击逻辑
        binding.bottomNav.setOnItemSelectedListener(item -> {
            int id = item.getItemId();
            if (id == R.id.nav_note) {
                replaceFragment(noteListFragment);
                return true;
            } else if (id == R.id.nav_add) {
                replaceFragment(addNoteFragment);
                return true;
            }
            return false;

        });
    }
    private void replaceFragment(@NonNull Fragment fragment){
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.fragment_container,fragment)
                .commit();
    }
}